package com.quan.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.quan.entity.Student;
import com.quan.mapper.StudentUseMaper;
import com.quan.mapper.StudentMapper;
import com.quan.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.collections.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;
    @Autowired
    private StudentUseMaper studentUseMaper;


    @Override
    public void addStudent(String students) {
        JSONObject jsonObject = JSONObject.parseObject(students);
        String str = jsonObject.getString("students");
        List<Student> studentsData =JSONArray.parseArray(str, Student.class);

        studentsData.stream().forEach(e ->
                studentMapper.insert(e));
//        studentMapper.insert(student);
    }

    @Override
    public void addStudentData(List<Student> students) {
        students.stream().forEach(e ->
                studentMapper.insert(e));

    }

    @Override
    public List<String> getStudentSalary() {
        return studentMapper.getStudentSalary();
    }

    @Override
    public List<Map<String,Object>> getStudent() {
        List<Map<String,Object>> student = studentUseMaper.getStudent();
        System.out.println(student+"  student");
        if(CollectionUtils.isNotEmpty(student)){
            System.out.println("包含 4");
        }

        List<Map<String,Object>> students = studentUseMaper.getStudentData();
        for (Map<String,Object> map : students) {
            System.out.println(map+"  map");
        }
        System.out.println(students+"  students");
        if(CollectionUtils.isNotEmpty(students)){
            System.out.println("包含 3");
        }
        return null;
    }

    @Override
    public List<Student> getStudentData() {
        List<Student> student = studentUseMaper.getStudentCeshi();
        System.out.println(student+"  student");
        if(CollectionUtils.isNotEmpty(student)){
            System.out.println("包含 4");
        }

        List<Student> students = studentUseMaper.getStudentDataCeshi();
        for (Student student1 : students) {
            System.out.println(student1+"  student1");
        }
        System.out.println(students+"  students");
        if(CollectionUtils.isNotEmpty(students)){
            System.out.println("包含 3");
        }
        return students;
    }


    @Override
    public List<Student> selectStudent() {
        Example e = new Example(Student.class);
        Example.Criteria c = e.createCriteria();

        Integer id=1;
        //关键字查询部分
//        String keyword = pageReq.getKeyword();
        c.orEqualTo("id", id).andLike("name",'%' + "张" + '%');
        //部门查询部门
        Example.Criteria criteria = e.createCriteria();
        e.and(criteria);

        List<Student> students = studentMapper.selectByExample(e);
        System.out.println(students+" +++");
        return null;
    }

}
